<?php
/**
 * | @author 大鹏^life <907215837@qq.com>
 * +----------------------------------------------------------------------
 * | @copyright 2016 - 2019 HQ
 * +----------------------------------------------------------------------
 * | @version $Id: 2019/4/25 16:23 jiahe_new Member.php 大鹏^life $
 * +----------------------------------------------------------------------
 */

namespace app\common\common\model\oldModel\order;

use app\common\common\model\oldModel\OldBase;

class  OrderItem extends OldBase  {
    protected $table = 'order_item';
    //错误消息
    public $error = '';
    //状态值
    public $status = true;
    //其他附带信息
    public $data = [];

    /**
     * 插入数据
     * @param $data
     * @return false|int
     */
    public function insertMember($data){
        return self::insertGetId($data);
    }

    /**
     * 订单详情和商品表关联
     * @param $storeId
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function allOrderGoods($order_id)
    {
        $where['oi.order_id'] = $order_id;

        $list = self::alias('oi')->field('oi.*,gd.*')
            -> join('goods gd', 'gd.goods_id=oi.goods_id AND gd.goods_id IS NULL')
            ->where($where)
            ->order('oi.create_time desc')
            ->selectToArray();
        return $list;
    }
    /**
     * 不带分页的多条查询
     * @param $where
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function allByWhere($where,$field = '*'){
        return $this->where($where)->field($field)->selectToArray();
    }

    /**
     * 带分页的查询
     * @param $where
     * @param $limit
     * @param string $order
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function selectByWhere($where, $limit, $order='id desc'){
        $list = $this->where($where)->limit($limit)->order($order)->select()->ToArray();
        $count = $this->where($where)->count();
        $this->data['count'] = $count;
        return $list;
    }

    /**
     * 查询单条数据
     * @param $where
     * @return array|false|\PDOStatement|string|\think\Model
     */
    public function findByWhere($where){
        return $this->where($where)->find();
    }

    /**
     * 通过open_id,修改用户信息
     * @param $open_id
     * @param $data
     * @return false|int
     */
    public function updateByOpenId($open_id, $data){
        return $this->save($data, ['open_id'=>$open_id]);
    }



}